<template>
  <div>
    <van-nav-bar safe-area-inset-top placeholder :title="$t('Setting')" left-arrow fixed @click-left="onClickLeft" />
    <div class="marginTop15">
      <!-- X1HybridG3 -->
      <van-cell-group v-if="inverterType==3">
        <van-cell :icon="imgArr.basic" :title="$t('BasicSetting')" is-link @click="jumps(1)" />
        <van-cell :icon="imgArr.advanced" :title="$t('AdvancedSetting')" is-link @click="pwdShow=true;setType=1" />
        <van-cell :icon="imgArr.super" :title="$t('SuperSetting')" is-link @click="pwdShow=true;setType=2" />
        <van-cell :icon="imgArr.meter" :title="$t('Meter')" is-link @click="pwdShow=true;setType=3" />
        <van-cell :icon="imgArr.rf" :title="$t('RFControl')" is-link @click="jumps(2)" />
      </van-cell-group>
      <!-- X3HybridG1 -->
      <van-cell-group v-if="inverterType==5">
        <van-cell :icon="imgArr.basic" :title="$t('BasicSetting')" is-link @click="jumps(1)" />
        <van-cell :icon="imgArr.advanced" :title="$t('AdvancedSetting')" is-link @click="pwdShow=true;setType=1" />
        <van-cell :icon="imgArr.super" :title="$t('SuperSetting')" is-link @click="pwdShow=true;setType=2" />
        <van-cell :icon="imgArr.meter" :title="$t('Meter')" is-link @click="pwdShow=true;setType=3" />
      </van-cell-group>
      <!-- X1BoostAirMini、X1BoostPro -->
      <van-cell-group v-if="inverterType==4||inverterType==8">
        <van-cell :icon="imgArr.basic" :title="$t('BasicSetting')" is-link @click="jumps(1)" />
        <van-cell :icon="imgArr.advanced" :title="$t('AdvancedSetting')" is-link @click="pwdShow=true;setType=1" />
        <van-cell :icon="imgArr.super" :title="$t('SuperSetting')" is-link @click="pwdShow=true;setType=2" />
        <van-cell :icon="imgArr.rf" :title="$t('RFControl')" is-link @click="jumps(2)" />
      </van-cell-group>
      <!-- X320K30K、X3Mic、X1AC、HybridA1、A1Fit、A1、X3MIC/PRO-G2 -->
      <van-cell-group v-if="inverterType==6||inverterType==7||inverterType==9||inverterType==10||inverterType==11||inverterType==12||inverterType==16">
        <van-cell :icon="imgArr.basic" :title="$t('BasicSetting')" is-link @click="jumps(1)" />
        <van-cell :icon="imgArr.advanced" :title="$t('AdvancedSetting')" is-link @click="pwdShow=true;setType=1" />
        <van-cell :icon="imgArr.super" :title="$t('SuperSetting')" is-link @click="pwdShow=true;setType=2" />
      </van-cell-group>
      <!-- J1ESSHB -->
      <van-cell-group v-if="inverterType==13">
        <van-cell :icon="imgArr.basic" :title="$t('BasicSetting')" is-link @click="jumps(1)" />
        <van-cell :icon="imgArr.advanced" :title="$t('AdvancedSetting')" is-link @click="pwdShow=true;setType=1" />
      </van-cell-group>
      <!-- 三相大功率机 -->
      <van-cell-group v-if="inverterType==100">
        <van-cell :icon="imgArr.basic" :title="$t('BasicSetting')" is-link @click="jumps(1)" />
        <van-cell :icon="imgArr.advanced" :title="$t('AdvancedSetting')" is-link @click="pwdShow=true;setType=1" />
        <van-cell :icon="imgArr.super" :title="$t('SuperSetting')" is-link @click="pwdShow=true;setType=2" />
      </van-cell-group>
      <van-dialog @confirm="pwdjumps" v-model="pwdShow" :title="$t('UnlockPwd')" :confirmButtonText="$t('OK')" :cancelButtonText="$t('Cancel')" width="200" show-cancel-button>
        <van-field :placeholder="$t('Password')" clearable v-model="pwd" type="digit" />
      </van-dialog>
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return {
      imgArr:{
        'basic':require('../../assets/setting1.png'),
        'advanced':require('../../assets/setting2.png'),
        'super':require('../../assets/setting3.png'),
        'meter':require('../../assets/setting4.png'),
        'rf':require('../../assets/setting5.png'),
      },
      inverterType:localStorage.getItem('inverterType'),
      transportType:localStorage.getItem('transportType'),
      pwdShow:false,
      setType:'',//1:advance 2:super 3:meter
      pwd:''
    }
  },
  methods: {
    onClickLeft(){
      this.$router.push({path:sessionStorage.getItem('setFrom')});
    },
    //无需密码(1:basic,2:RF)
    jumps(category){
      if(category==1){
        if(this.transportType==1){
          if(this.inverterType==3){
            this.$router.push({path:'/x1hybridg3basicPT'});
          }else if(this.inverterType==4){
            this.$router.push({path:'/x1boostairminibasicPT'});
          }else if(this.inverterType==5){
            this.$router.push({path:'/x3hybridg1basicPT'});
          }else if(this.inverterType==6){
            this.$router.push({path:'/x320k30kbasicPT'});
          }else if(this.inverterType==7){
            this.$router.push({path:'/x3micbasicPT'});
          }else if(this.inverterType==8){
            this.$router.push({path:'/x1boostprobasic'});
          }else if(this.inverterType==9){
            this.$router.push({path:'/x1acbasic'});
          }else if(this.inverterType==10||this.inverterType==12){
            this.$router.push({path:'/hybrida1basic'});
          }else if(this.inverterType==11){
            this.$router.push({path:'/a1fitbasic'});
          }else if(this.inverterType==13){
            this.$router.push({path:'/j1esshbbasic'});
          }else if(this.inverterType==16){
            this.$router.push({path:'/x3micprog2basic'});
          }else if(this.inverterType==100){
            this.$router.push({path:'/x3bigbasic'});
          }
        }else{
          if(this.inverterType==3){
            this.$router.push({path:'/x1hybridg3basic'});
          }else if(this.inverterType==4){
            this.$router.push({path:'/x1boostairminibasic'});
          }else if(this.inverterType==5){
            this.$router.push({path:'/x3hybridg1basic'});
          }else if(this.inverterType==6){
            this.$router.push({path:'/x320k30kbasic'});
          }else if(this.inverterType==7){
            this.$router.push({path:'/x3micbasic'});
          }
        }
      }else{
        this.$router.push({path:'/rfcontrol'});
      }
    },
    //需要密码
    async pwdjumps(){
      if(this.pwd==''){
        this.comm.tipsShow('PwdNotEmpty');
      }else{
        this.comm.loadingShow();
        if(this.transportType==1){
          let formData=[{"reg":0,"val":this.pwd}];
          let data=await this.SETAPI.setInvMachinePT(localStorage.getItem('domain'), {
            'optType':'setReg',
            'sn':localStorage.getItem('wifiSN'),
            'tokenId':localStorage.getItem('tokenId'),
            'num':1,
            'Data':JSON.stringify(formData)
          });
          if (data.success) {
            if(this.inverterType==3){
              if(this.setType==1){
                this.$router.push({path:'/x1hybridg3advancedPT'});
              }else if(this.setType==2){
                this.$router.push({path:'/x1hybridg3superPT'});
              }else if(this.setType==3){
                this.$router.push({path:'/meterPT'});
              }
            }else if(this.inverterType==4){
              if(this.setType==1){
                this.$router.push({path:'/x1boostairminiadvancedPT'});
              }else if(this.setType==2){
                this.$router.push({path:'/x1boostairminisuperPT'});
              }
            }else if(this.inverterType==5){
              if(this.setType==1){
                this.$router.push({path:'/x3hybridg1advancedPT'});
              }else if(this.setType==2){
                this.$router.push({path:'/x3hybridg1superPT'});
              }else if(this.setType==3){
                this.$router.push({path:'/meterPT'});
              }
            }else if(this.inverterType==6){
              if(this.setType==1){
                this.$router.push({path:'/x320k30kadvancedPT'});
              }else if(this.setType==2){
                this.$router.push({path:'/x320k30ksuperPT'});
              }
            }else if(this.inverterType==7){
              if(this.setType==1){
                this.$router.push({path:'/x3micadvancedPT'});
              }else if(this.setType==2){
                this.$router.push({path:'/x3micsuperPT'});
              }
            }else if(this.inverterType==8){
              if(this.setType==1){
                this.$router.push({path:'/x1boostproadvanced'});
              }else if(this.setType==2){
                this.$router.push({path:'/x1boostprosuper'});
              }
            }else if(this.inverterType==9){
              if(this.setType==1){
                this.$router.push({path:'/x1acadvanced'});
              }else if(this.setType==2){
                this.$router.push({path:'/x1acsuper'});
              }
            }else if(this.inverterType==10||this.inverterType==12){
              if(this.setType==1){
                this.$router.push({path:'/hybrida1advanced'});
              }else if(this.setType==2){
                this.$router.push({path:'/hybrida1super'});
              }
            }else if(this.inverterType==11){
              if(this.setType==1){
                this.$router.push({path:'/a1fitadvanced'});
              }else if(this.setType==2){
                this.$router.push({path:'/a1fitsuper'});
              }
            }else if(this.inverterType==13){
              if(this.setType==1){
                this.$router.push({path:'/j1esshbadvanced'});
              }
            }else if(this.inverterType==16){
              if(this.setType==1){
                this.$router.push({path:'/x3micprog2advanced'});
              }else if(this.setType==2){
                this.$router.push({path:'/x3micprog2super'});
              }
            }else if(this.inverterType==100){
              if(this.setType==1){
                this.$router.push({path:'/x3bigadvanced'});
              }else if(this.setType==2){
                this.$router.push({path:'/x3bigsuper'});
              }
            }
          }else {
            this.comm.tipsShow('UnlockFaild');
          }
        }else{
          let data=await this.SETAPI.setInvMachine(localStorage.getItem('domain'), {
            'optType':'Password',
            'sn':localStorage.getItem('wifiSN'),
            'tokenId':localStorage.getItem('tokenId'),
            'PasswordValue':this.pwd
          });
          if (data.success) {
            if(this.inverterType==3){
              if(this.setType==1){
                this.$router.push({path:'/x1hybridg3advanced'});
              }else if(this.setType==2){
                this.$router.push({path:'/x1hybridg3super'});
              }else if(this.setType==3){
                this.$router.push({path:'/meter'});
              }
            }else if(this.inverterType==4){
              if(this.setType==1){
                this.$router.push({path:'/x1boostairminiadvanced'});
              }else if(this.setType==2){
                this.$router.push({path:'/x1boostairminisuper'});
              }
            }else if(this.inverterType==5){
              if(this.setType==1){
                this.$router.push({path:'/x3hybridg1advanced'});
              }else if(this.setType==2){
                this.$router.push({path:'/x3hybridg1super'});
              }else if(this.setType==3){
                this.$router.push({path:'/meter'});
              }
            }else if(this.inverterType==6){
              if(this.setType==1){
                this.$router.push({path:'/x320k30kadvanced'});
              }else if(this.setType==2){
                this.$router.push({path:'/x320k30ksuper'});
              }
            }else if(this.inverterType==7){
              if(this.setType==1){
                this.$router.push({path:'/x3micadvanced'});
              }else if(this.setType==2){
                this.$router.push({path:'/x3micsuper'});
              }
            }
          }else {
            this.comm.tipsShow('UnlockFaild');
          }
        }
      }
    }
  }
}
</script>

<style scoped lang="less">

</style>
